//  [10/18/2013 OMEGA] created

#include "DuelECCommon.h"
#include "DuelECSelectionMask.h"

namespace DuelEC
{

	DECSelectionMask::DECSelectionMask()
	{

	}

	DECSelectionMask::DECSelectionMask( const DECSelectionMask& in )
	{
		mMaskMap = in.mMaskMap;
	}

	DECSelectionMask::~DECSelectionMask()
	{

	}

	void DECSelectionMask::enableSelectable( DECObjectTypeID id )
	{
		mMaskMap[id] = true;
	}

	void DECSelectionMask::disableSelectable( DECObjectTypeID id )
	{
		mMaskMap[id] = false;
	}

	void DECSelectionMask::setSelectable( DECObjectTypeID id, bool flag )
	{
		mMaskMap[id] = flag;
	}

	DECSelectionMask DECSelectionMask::operator|( DECObjectTypeID selType )
	{
		DECSelectionMask ret(*this);
		ret.enableSelectable(selType);
		return ret;
	}

	DECSelectionMask DECSelectionMask::operator|( DECSelectionMask& mask )
	{
		DECSelectionMask ret(*this);
		MaskMap::iterator i;
		for ( i = mask.mMaskMap.begin(); i != mask.mMaskMap.end(); ++i)
		{
			// only process those disabled type.
			if (i.value() == false)
			{
				MaskMap::iterator locVal = mMaskMap.find(i.key());
				if (locVal != mMaskMap.end()) // means this type in this map is defined, i.e it maybe false.
				{
					// value decided by local value if the other mask value is false.
					ret.mMaskMap[i.key()] = locVal.value(); 
				}
			}
		}
		return ret;
	}

	DECSelectionMask& DECSelectionMask::operator=( const DECSelectionMask& other )
	{
		mMaskMap = other.mMaskMap;
		return *this;
	}

	bool DECSelectionMask::queryEnabled( DECObjectTypeID id )
	{
		MaskMap::iterator i = mMaskMap.find(id);
		if (i == mMaskMap.end())
		{
			return true;
		}
		return i.value();
	}

}